﻿using System.Web.Mvc;
using log4net;


namespace CEIT.MVC3.Web.Controllers
{
    [HandleError]
    public class ControllerCustom : Controller
    {
        /// <summary>
        /// p.eduardo.silva - 20130319:
        /// TempData de retorno de mensagem do sistema
        /// </summary>
        public string _Feedback { get { return (TempData["Feedback"] != null) ? (string)TempData["Feedback"] : string.Empty; } set { TempData["Feedback"] = value; } }

        /// <summary>
        /// p.eduardo.silva - 20130601:
        /// Grava log diário de atividades inesperadas do sistema
        /// </summary>
        public ILog _ObjLog { get { return LogManager.GetLogger("LogInFile"); } }

        public string _Anonimo { get { return "(Anônimo)"; } }

        public string _LoginRoot { get { return "root"; } }

        public string _PassRoot { get { return "admin"; } }

        /// <summary>
        /// p.eduardo.silva - 20130609:
        /// Solução javascript para evento pós ajax load.
        /// </summary>
        public string _JS {
                get{ 
                    return "<script type='text/javascript'> "+
                        "    $(document).ready(function () { "+
                        "        $.datepicker.setDefaults($.datepicker.regional['']); "+
                        "        $('.datepicker').datepicker($.datepicker.regional['pt-BR']); "+
                        "        $('.datepicker').datepicker({ "+
                        "            inline: true, "+
                        "            changeMonth: true, "+
                        "            changeYear: true "+
                        "        }); "+
                        " "+
                        "        jQuery(function ($) { "+
                        "            $('.decimal').setMask('decimal'); "+
                        "            $('.datepicker').setMask('date'); "+
                        "            $('.integer').setMask('999'); "+
                        "        }); "+
                        "    }); "+
                        "  "+
                        "    function MoneyToFloat(valor) { "+
                        "        return parseFloat(getNum(valor.replace(/\\s/g, '').replace('.', '').replace('.', '').replace('.', '').replace('.', '').replace(',', '.'))); "+
                        "    } "+
                        " "+
                        "    function getNum(num) { "+
                        "        if (num == '' || (num + 0) == 0) "+
                        "            num = '0'; "+
                        "        return num; "+
                        "    } "+
                        " "+
                        "    function parseMoney(num) { "+
                        "        var x = 0; "+
                        " "+
                        "        num = getNum(num); "+
                        " "+
                        "        if (num < 0) { "+
                        "            num = Math.abs(num); "+
                        "            x = 1; "+
                        "        } "+
                        "        if (isNaN(num)) "+
                        "            num = '0'; "+
                        " "+
                        "        cents = Math.floor((num * 100 + 0.5) % 100); "+
                        "        num = Math.floor((num * 100 + 0.5) / 100).toString(); "+
                        " "+
                        "        if (cents < 10) "+
                        "            cents = '0' + cents; "+
                        " "+
                        "        for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++) "+
                        "            num = num.substring(0, num.length - (4 * i + 3)) + '.' + num.substring(num.length - (4 * i + 3)); "+
                        " "+
                        "        ret = num + ',' + cents; "+
                        " "+
                        "        if (x == 1) "+
                        "            ret = ' - ' + ret; "+
                        " "+
                        "        return ret; "+
                        "    } "+
                        " "+
                        "</script>";
                }
        }
        
    }
}

